package com.mojo.io.stream;

import java.io.*;
import java.nio.charset.StandardCharsets;

/**
 * @author <a href="mailto:sjj@jianzhimao.com">mojo</a>
 * copyright (C), 2013-2022, 广州九尾信息科技有限公司
 * @date 2022/3/29 15:05
 */
public class BufferedStream01 {
    public static void main(String[] args) {
        //bufferInput();
        bufferReader();
    }

    private static void bufferReader() {
        try (BufferedReader reader = new BufferedReader(new FileReader("e:\\a.txt"))) {
            String s;
            while ((s = reader.readLine()) != null) {
                System.out.println(s);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    private static void bufferInput() {
        try (BufferedInputStream stream = new BufferedInputStream(new FileInputStream("e:\\a.txt"))) {
            byte[] b = new byte[48];
            int n;
            while ((n = stream.read(b, 0, b.length)) != -1) {
                System.out.println(new String(b, 0, n, StandardCharsets.UTF_8));
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
